﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TextDecoder : MonoBehaviour
{
    public SpriteRenderer PictureRenderer;

    private const float SpawnInterval = 0.1f;

    public int SpawnNum = 10;
    private int mCurrentSpawnNum;
    private bool bFinished = false;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!bFinished && (collision.gameObject.layer == PhysicsLayer.Text || collision.gameObject.layer == PhysicsLayer.Player))
        {
            bFinished = true;
            StartCoroutine(FinishGame());
        }
    }
    IEnumerator FinishGame()
    {
        //PictureRenderer.sprite = PictureLogicScript.sGetInstance().GetSprite();
        PictureRenderer.size = new Vector2(4f, 0f);
        mCurrentSpawnNum = 0;
        while (mCurrentSpawnNum < SpawnNum)
        {
            mCurrentSpawnNum++;
            PictureRenderer.size = new Vector2(4f, (float)mCurrentSpawnNum / SpawnNum * 3f);
            yield return new WaitForSeconds(SpawnInterval);
        }
        GameManager.GetInstance().ShowResult();
    }
}
